{include file='public/header' /}
</head>
<body style="background: #1E9FFF">
    <div style="position: absolute;left: 50%;top: 50%; width: 500px; margin-left: -250px;margin-top: -200px">
        <div style="background: #EEEEEE;padding:20px;border-radius:4px;box-shadow: 5px 5px 20px #444444;  ">
            <div class="layui-form">
                <div class="layui-form-item" style="color: gray">
                    <h2>桃苑后台管理系统</h2>
                </div>
                <hr>
                <div class="layui-form-item">
                    <label class="layui-form-label">帐&nbsp&nbsp&nbsp&nbsp号:</label>
                    <div class="layui-input-inline">
                        <input type="username" name="username" id="username" required lay-verify="username" placeholder="请输入帐号" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">   </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">密&nbsp&nbsp&nbsp&nbsp码:</label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">姓&nbsp&nbsp&nbsp&nbsp名:</label>
                    <div class="layui-input-inline">
                        <input type="name" name="name" id="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号:</label>
                    <div class="layui-input-inline">
                        <input type="phone" name="phone" id="phone" required lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身&nbsp;&nbsp;&nbsp;&nbsp;份</label>
                    <div class="layui-input-inline">
                        <select name="gid">
                            <option></option>
                            {volist name="title" id="vo"}
                            {if $vo.gid==1}
                            {else /}
                            <option value="{$vo.gid}" >{$vo.title}</option>
                            {/if}
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">验证码:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="verifycode" id="verifycode" placeholder="请输入验证码" class="layui-input">
                    </div>
                    <img src="{:captcha_src()}" alt="captcha" id="img" onclick="reloadImg()">
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
<!--                        <button class="layui-btn" onclick="dologin();return false;">登录</button>-->
                        <button class="layui-btn layui-btn-warm" lay-submit lay-filter="signin" >注册</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.use(['layer','form'],function(){
            form = layui.form;
            layer = layui.layer;
            $ = layui.jquery;
            // 用户名控件获取焦点
            $('#username').focus();
            // 回车登录
            $('input').keydown(function(e){
                if(e.keyCode == 13){
                    $(".layui-btn-warm").click();
                    //signin();
                }
            });
            form.on('submit(signin)', function(data){
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                console.log(data) //当前容器的全部表单字段，名值对形式：{name: value}
                //$.post('url',{data},function () {},'json');
                $.post('__PUBLIC__/admin/Account/signin',{'username':data.field.username,'password':data.field.password,'verifycode':data.field.verifycode,'name':data.field.name,'phone':data.field.phone,'gid':data.field.gid},function (res){
                    if(res.code>0){
                        reloadImg();//使用reloadImg重 新加载验证码
                        layer.msg(res.msg,{icon:res.code});
                    }else {
                        layer.msg(res.msg);
                        window.location.href = '__PUBLIC__/admin/Home/index';
                    }
                },'json');


                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
            //自定义验证规则
            form.verify({
                phone: [/^1[3|4|5|7|8]\d{9}$/, "手机必须11位，只能是数字！"]
                ,password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格']
                ,gid: function(value, item){ //value：表单的值、item：表单的DOM对象
                    console.log(value)
                    if(value==''){
                        return '请选择身份';
                    }
                }
                ,verifycode:function(value, item){ //value：表单的值、item：表单的DOM对象
                    console.log(value)
                    if(value==''){
                        return '填写验证码';
                    }
                }
                //
                ,username: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                        return '用户名不能有特殊字符';
                    }
                    if(/(^\_)|(\__)|(\_+$)/.test(value)){
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if(/^\d+\d+\d$/.test(value)){
                        return '用户名不能全为数字';
                    }
                }
                ,name: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                        return '姓名不能有特殊字符';
                    }
                }
            });
        });
        // 重新生成验证码
        function reloadImg(){
            $('#img').attr('src','{:captcha_src()}?rand='+Math.random());
        }
        //登录
        // function signin(){
        //     var username = $.trim($('#username').val());
        //     var pwd = $.trim($('#password').val());
        //     var verifycode = $.trim($('#verifycode').val());
        //     var name = $.trim($('#name').val());
        //     var phone = $.trim($('#phone').val());
        //     var gid = $('select[name="gid"]').val();
        //     //自定义验证规则
        //     form.verify({
        //         phone: [/^1[3|4|5|7|8]\d{9}$/, "手机必须11位，只能是数字！"]
        //         ,username: function(value, item){ //value：表单的值、item：表单的DOM对象
        //             if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
        //                 return '用户名不能有特殊字符';
        //             }
        //             if(/(^\_)|(\__)|(\_+$)/.test(value)){
        //                 return '用户名首尾不能出现下划线\'_\'';
        //             }
        //             if(/^\d+\d+\d$/.test(value)){
        //                 return '用户名不能全为数字';
        //             }
        //         }
        //     });
        //     if(username == ''){
        //         layer.alert('请输入用户名',{icon:2});
        //         return;
        //     }
        //     if(pwd == ''){
        //         layer.alert('请输入密码',{icon: 2});
        //         return;
        //     }
        //     if(name == ''){
        //         layer.alert('请输入姓名',{icon: 2});
        //         return;
        //     }
        //     if(phone == ''){
        //         layer.alert('请输入手机号',{icon: 2});
        //         return;
        //     }
        //     if(gid == 0){
        //         layer.alert('请选择身份',{icon: 2});
        //         return;
        //     }
        //     if(verifycode == ''){
        //         layer.alert('请输入验证码',{icon: 2});
        //         return;
        //     }
        //     //$.post('url',{data},function () {},'json');
        //     $.post('__PUBLIC__/admin/Account/signin',{'username':username,'pwd':pwd,'verifycode':verifycode,'name':name,'phone':phone,'gid':gid},function (res){
        //         if(res.code>0){
        //             reloadImg();//使用reloadImg重 新加载验证码
        //             layer.alert(res.msg,{icon:2});
        //         }else {
        //             layer.msg(res.msg);
        //             window.location.href = '__PUBLIC__/admin/Home/index';
        //         }
        //     },'json');
        //}
    </script>
</body>
</html>